<?php

namespace app\admin\service;

use app\admin\dao\AccountBillDao;
use app\admin\model\UM as UM;
use app\common\model\Role;
use ShidianUtil\Utils\StringUtil;
use ShidianUtil\Utils\TimeUtil;

/**
 * Class CompanyBillService
 * @package app\admin\service
 */
class CompanyBillService
{
    // dao
    private AccountBillDao $accountBillDao;

    public function __construct(AccountBillDao $accountBillDao)
    {
        $this->accountBillDao = $accountBillDao;
    }

    /**
     *
     * @param UM|null $user
     * @param $companyId
     * @param int|null $page
     * @param int|null $page_size
     * @return array
     */
    public function index(UM $user, $companyId, $startTime, $endTime, ?int $page = null, ?int $page_size = null): array
    {
        if (StringUtil::equals($user->roleType, Role::ROLE_TYPE_COMPANY)) {
            $companyId = $user->id;
        }

        if(is_numeric($endTime)){
            $endTime = TimeUtil::stamp(TimeUtil::DAY, $endTime, false);
        }

        //这里如果要修改查询，建议把查询放到dao层去
        return $this->accountBillDao->listBillByCompany($companyId, $startTime, $endTime, $page, $page_size);
    }

}
